<?php

declare (strict_types = 1);

namespace app\controller\develop;

use app\BaseController;
use app\service\develop\ApplyService;

/**
 * 应用图标
 */
class Apply extends BaseController
{
    protected $applyServer;

    public function initialize()
    {
        $this->applyServer = make(ApplyService::class);
    }
    /**
     * 应用图库列表
     */
    public function mapList()
    {
        return $this->success($this->applyServer->mapList($this->paging()));
    }
    /**
     * 应用图库编辑
     */
    public function mapEdit()
    {
        $data = $this->request->post();
        $this->validate($data, [
            'location|位置' => 'require|in:1',
            'title|标题' => 'require|length:1,30',
            'image|图片' => 'require|min:1',
            'jump_type|跳转' => 'integer:in:0,1,2',
            'sort' => 'integer|egt:0|elt:255',
            'status' => 'integer|in:0,1',
        ]);
        return $this->applyServer->mapEdit($data, (int) $data['id']) ? $this->success() : $this->error('保存失败');
    }
    /**
     * 应用图库状态修改
     */
    public function mapStatus()
    {
        $param = $this->request->post();
        return $this->applyServer->mapStatus((int)$param['id']) ? $this->success() : $this->error('修改失败');
    }
    /**
     * 应用图库删除
     */
    public function mapDelete()
    {
        $param = $this->request->post();
        return $this->applyServer->mapDelete($param['ids']) ? $this->success() : $this->error('删除失败');
    }
    /**
     * 应用中心列表
     */
    public function centerList()
    {
        return $this->success($this->applyServer->centerList($this->paging()));
    }
    /**
     * 应用中心编辑
     */
    public function centerEdit()
    {
        $data = $this->request->post();
        $this->validate($data, [
            'location|位置' => 'require|in:1,2',
            'name|名称' => 'require|length:1,30',
            'tag|应用标识' => 'require|length:1,20',
            'icon|图标' => 'min:0',
            'jump_type|跳转' => 'integer:in:0,1,2',
            'sort' => 'integer|egt:0|elt:255',
            'status' => 'integer|in:0,1',
        ]);
        return $this->applyServer->centerEdit($data, (int) $data['id']) ? $this->success() : $this->error('保存失败');
    }
    /**
     * 应用状态修改
     */
    public function centerStatus()
    {
        $param = $this->request->post();
        return $this->applyServer->centerStatus((int)$param['id']) ? $this->success() : $this->error('修改失败');
    }
    /**
     * 应用中心删除
     */
    public function centerDelete()
    {
        $param = $this->request->post();
        return $this->applyServer->centerDelete($param['ids']) ? $this->success() : $this->error('删除失败');
    }
}